<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMqttLogTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('mqtt_log', function (Blueprint $table) {
            $table->string("id", 20)->comment("ID");
            $table->string("cmd", 50)->comment("命令名");
            $table->text("params")->comment("参数");
            $table->tinyInteger("status")->default(0)->comment("状态,0:初始,1:完成");
            $table->tinyInteger("isDeleted")->default(0)->comment("是否删除,0:未删除,1:已删除");
            $table->integer("createdAt")->comment("创建时间");
            $table->integer("updatedAt")->comment("修改时间");
            $table->index("createdAt", "idx_created_at");
            $table->index("status", "idx_status");
            $table->index("isDeleted", "idx_is_deleted");
            $table->primary("id");
            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}mqtt_log` COMMENT = 'MQTT 日志表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('mqtt_log');
    }
}
